<!DOCTYPE html>
<html>
<head>
  <meta charset="UTF-8">
  <title>Document</title>
  <style>
    
  </style>
</head>
<body>
  
</body>
<script>

  // function fn(n){
  //   const obj = {}
  //   obj.name = n
  //   obj.sayHi = fn.lyObj.sayHi;
  //   return obj;
  // }

  // fn.lyObj = {};
  // fn.lyObj.sayHi = function(){
  //   console.log("Hi, " + this.name)
  // }

  // const o1 = fn("admin")
  // console.log(o1);
  // o1.sayHi();
  
  // const o2 = fn("root")
  // console.log(o2);
  // o2.sayHi();

  // console.log(o1.sayHi === o2.sayHi);

  // 以上工厂模式已被废弃
  // =========
  // 官方新增了内置的工厂模式
    // 构造自定义函数
  
  // function fn(n){
  //   this.name = n;
  // }
  // fn.prototype.sayHi = function(){
  //   console.log("Hi, " + this.name)
  // }

  // const o1 = new fn("admin")
  // console.log(o1);
  // o1.sayHi();
  
  // const o2 = new fn("root")
  // console.log(o2);
  // o2.sayHi();

  // console.log(o1.sayHi === o2.sayHi);

  // ============
  // ES6新增的工厂模式

  class fn{
    constructor(n){
      this.name = n
    }
    sayHi(){
      console.log("Hi, " + this.name)
    }
  }

  const o1 = new fn("admin")
  console.log(o1);
  o1.sayHi();
  
  const o2 = new fn("root")
  console.log(o2);
  o2.sayHi();

  console.log(o1.sayHi === o2.sayHi);



</script>
</html>